package kgc.qy.service.impl;

import com.alibaba.druid.util.StringUtils;
import kgc.qy.mapper.SysUsersMapper;
import kgc.qy.pojo.SysUsers;
import kgc.qy.service.IAuthorService;
import kgc.qy.util.CommonResult;
import kgc.qy.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AuthorServiceImpl implements IAuthorService {
    @Autowired
    private SysUsersMapper sysUsersMapper;

    @Override
    public CommonResult<SysUsers> login(String account, String password) {
        //账号与密码不能为空
        if (StringUtils.isEmpty(account))
            return new CommonResult<SysUsers>(400,"账号不能为空",null);
        if (StringUtils.isEmpty(password))
            return new CommonResult<SysUsers>(400,"密码不能为空",null);
        //密码加密
        password = MD5.getMd5(password,32);
        SysUsers users = sysUsersMapper.selectByUserAccountAndPwd(account, password);
        if (users == null)
            return new CommonResult<SysUsers>(500,"账号或密码不正确",null);
        //判断用户账号是否被禁用
        if(users.getStatus() == 1)
            return new CommonResult<>(202, "该账号已被禁用，请联系管理员解禁", null);
        //登录成功
        return new CommonResult<SysUsers>(200,"登录成功",users);
    }
}
